// UpdateCallback.h

#ifndef __UPDATECALLBACK_H
#define __UPDATECALLBACK_H

#include "Common/COM/IPassword.h"
#include "Common/COM/ICoder.h"

#include "UpdatePair.h"
#include "UpdateProduce.h"


#include <vector>


struct IUpdateCallbackUI
{
  STDMETHOD(SetTotal)(UINT64 size) PURE;
  STDMETHOD(SetCompleted)(const UINT64 *completeValue) PURE;
  STDMETHOD(SetRatioInfo)(const UINT64 *inSize, const UINT64 *outSize) PURE;
  STDMETHOD(CheckBreak)() PURE;
  STDMETHOD(Finilize)() PURE;
  STDMETHOD(SetNumFiles)(UINT64 numFiles) PURE;
  STDMETHOD(GetStream)(const wchar_t *name, bool isAnti) PURE;
  STDMETHOD(OpenFileError)(const wchar_t *name, DWORD systemError) PURE;
  STDMETHOD(SetOperationResult)(INT32 operationResult) PURE;
  STDMETHOD(CryptoGetTextPassword2)(INT32 *passwordIsDefined, BSTR *password) PURE;
  STDMETHOD(CryptoGetTextPassword)(BSTR *password) PURE;
  /* STDMETHOD(ShowDeleteFile(const wchar_t *name)PURE; */ 
  /* STDMETHOD(CloseProgress() { return S_OK; }; */
};

namespace Common
{
namespace Archive
{

	// used only in AgentOut.h and cpp in FM

class ATL_NO_VTABLE CArchiveUpdateCallback:
	public CComObjectRootEx<CComSingleThreadModel>,
  public IArchiveUpdateCallback2,
  public ICryptoGetTextPassword2,
  public ICryptoGetTextPassword,
  public ICompressProgressInfo
{
public:
	BEGIN_COM_MAP(CArchiveUpdateCallback)
		COM_INTERFACE_ENTRY(IArchiveUpdateCallback2)
		COM_INTERFACE_ENTRY(ICryptoGetTextPassword2)
		COM_INTERFACE_ENTRY(ICryptoGetTextPassword)
		COM_INTERFACE_ENTRY(ICompressProgressInfo)
	END_COM_MAP()



	DECLARE_PROTECT_FINAL_CONSTRUCT()

	HRESULT FinalConstruct()
	{
		return S_OK;
	}

	void FinalRelease()
	{
	}


  STDMETHOD(SetRatioInfo)(const UINT64 *inSize, const UINT64 *outSize);

    /* INTERFACE IProgress */ 
  STDMETHOD(SetTotal)(UINT64 total) ;
  STDMETHOD(SetCompleted)(const UINT64 *completeValue) ;
  
  /* INTERFACE IArchiveUpdateCallback */
  STDMETHOD(GetUpdateItemInfo)(UINT32 index,  
      INT32 *newData, /*1 - new data, 0 - old data */ 
      INT32 *newProperties, /* 1 - new properties, 0 - old properties */ 
      UINT32 *indexInArchive /* -1 if there is no in archive, or if doesn't matter */ 
      )  ;
  STDMETHOD(GetProperty)(UINT32 index, PROPID propID, PROPVARIANT *value) ;
  STDMETHOD(GetStream)(UINT32 index, ISequentialInStream **inStream) ;
  STDMETHOD(SetOperationResult)(INT32 operationResult) ;
  
  // Interface IArchiveUpdateCallback2
  STDMETHOD(GetVolumeSize)(UINT32 index, UINT64 *size) ; 
  STDMETHOD(GetVolumeStream)(UINT32 index, ISequentialOutStream **volumeStream) ;

  STDMETHOD(CryptoGetTextPassword2)(INT32 *passwordIsDefined, BSTR *password);
  STDMETHOD(CryptoGetTextPassword)(BSTR *password);

public:
	std::vector<UINT64> VolumesSizes;
  CString VolName;
  CString VolExt;

  IUpdateCallbackUI *Callback;

  bool ShareForWrite;
  bool StdInMode;
  const Common::FileSystem::CDirItems *DirItems;
  const std::vector<Common::FileSystem::CArcItem> *ArcItems;
  const std::vector<Common::Archive::CUpdatePair2> *UpdatePairs;
  const CStringVector *NewNames;
  CComPtr<IInArchive> Archive;

  CArchiveUpdateCallback();
};

}
}

#endif
